package cn.tedu.csmall.product.controller;

import cn.tedu.csmall.product.pojo.dto.PictureAddNewDTO;
import cn.tedu.csmall.product.service.IPictureService;
import cn.tedu.csmall.product.web.JsonResult;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

@RestController
@Slf4j
@RequestMapping("/pictures")
@Api(tags = "7.照片管理")
public class PictureController {

    @Autowired
    IPictureService pictureService;

    @PostMapping("/add-new")
    @ApiOperation("添加照片")
    @ApiOperationSupport(order = 100)
    public JsonResult<Void> addNew(@Valid PictureAddNewDTO pictureAddNewDTO){
        log.debug("开始处理【添加图片】请求，pictureAddNewDTO={}",pictureAddNewDTO);
        pictureService.addNew(pictureAddNewDTO);
        return JsonResult.ok();
    }

    @PostMapping("/{id:[0-9]+}/deleteById")
    @ApiOperation("根据id删除照片")
    @ApiOperationSupport(order = 200)
    @ApiImplicitParam(name = "id",value = "照片id",required = true,dataType = "long")
    public JsonResult<Void> deleteById(@PathVariable Long id){
        log.debug("准备处理【根据id删除照片】请求，id={}",id);
        pictureService.delete(id);
        return JsonResult.ok();
    }
}
